const state = {
  stars: 0,
  currentTheme: null,
  difficulty: 'easy',
  score: 0,
  gameContent: [],
  unlockedThemes: ['colors'] // 默认解锁颜色主题
}

const getters = {
  isThemeUnlocked: (state) => (themeId) => {
    return state.unlockedThemes.includes(themeId)
  }
}

const mutations = {
  SET_STARS(state, stars) {
    state.stars = stars
  },
  SET_CURRENT_THEME(state, theme) {
    state.currentTheme = theme
  },
  SET_DIFFICULTY(state, difficulty) {
    state.difficulty = difficulty
  },
  SET_SCORE(state, score) {
    state.score = score
  },
  SET_GAME_CONTENT(state, content) {
    state.gameContent = content
  }
}

const actions = {
  loadProgress({ commit }) {
    const progress = uni.getStorageSync('gameProgress') || { stars: 0 }
    commit('SET_STARS', progress.stars)
  },

  handleAnswer({ commit, state }, isCorrect) {
    if (isCorrect) {
      commit('SET_SCORE', state.score + 1)
    }
  },

  startGame({ commit }, { theme, difficulty }) {
    commit('SET_CURRENT_THEME', theme)
    commit('SET_DIFFICULTY', difficulty)
    commit('SET_SCORE', 0)
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
} 